//
//  MessageSetV.swift
//  Employee
//
//  Created by swordjoy on 2017/3/31.
//  Copyright © 2017年 remotevillage. All rights reserved.
//

import UIKit

class MessageSetV: UIView {

  var model: ChatUser? {
    
    didSet {
      
      guard let temp = model else { return }
      
      headIcon.setImage(with: temp.headIconUrl, placeholder: GlobalConfig.DefaultHeadIconImage)
      nickname.text = temp.nickname
      phoneNumber.text = temp.phoneNumber
      department.text = temp.department
      
    }
    
  }
  
  fileprivate var contentV: UIView!
  
  fileprivate var headIcon: UIImageView!
  fileprivate var nickname: UILabel!
  fileprivate var phoneNumber: UILabel!
  fileprivate var department: UILabel!
  
  override init(frame: CGRect) {
    super.init(frame: frame)
    backgroundColor = UIColor.clear
    
    create()
    
  }
  
  required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }

}

// MARK: - layout
extension MessageSetV {
  
  func create() {
    
    contentV = UIView()
    addSubview(contentV)
    contentV.backgroundColor = UIColor.white
    contentV.snp.makeConstraints { (make) in
      make.left.equalTo(10)
      make.top.equalTo(13)
      make.right.equalTo(-10)
      make.bottom.equalTo(-5)
    }
    contentV.layer.cornerRadius = 4
    contentV.clipsToBounds = true
    
    headIcon = UIImageView()
    contentV.addSubview(headIcon)
    headIcon.image = GlobalConfig.DefaultHeadIconImage
    headIcon.snp.makeConstraints { (make) in
      make.height.width.equalTo(50)
      make.centerY.equalToSuperview()
      make.left.equalTo(10)
    }
    headIcon.layer.cornerRadius = 4
    headIcon.clipsToBounds = true
    
    nickname = UILabel()
    contentV.addSubview(nickname)
    nickname.font = GlobalConfig.system16Font
    nickname.textColor = GlobalConfig.TextDeepColor
    nickname.snp.makeConstraints { (make) in
      make.left.equalTo(headIcon.snp.right).offset(12)
      make.top.equalTo(18)
      make.height.equalTo(16)
    }
    
    phoneNumber = UILabel()
    contentV.addSubview(phoneNumber)
    phoneNumber.font = GlobalConfig.system14Font
    phoneNumber.textColor = GlobalConfig.TextDeepColor
    phoneNumber.snp.makeConstraints { (make) in
      make.left.equalTo(headIcon.snp.right).offset(12)
      make.top.equalTo(nickname.snp.bottom).offset(8)
      make.height.equalTo(14)
    }
    
    department = UILabel()
    contentV.addSubview(department)
    department.font = GlobalConfig.system12Font
    department.textColor = GlobalConfig.TextLightColor
    department.snp.makeConstraints { (make) in
      make.centerY.equalTo(nickname.snp.centerY)
      make.right.equalTo(-15)
    }
    
  }
}

